<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="csrf-token" content="{{csrf_token()}}">
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        
        
        <link rel="stylesheet" href="{{URL::asset('resources/xadmin/css/font.css')}}">
        <link rel="stylesheet" href="{{URL::asset('resources/xadmin/css/xadmin.css')}}">
        <link rel="stylesheet" href="{{URL::asset('resources/xadmin/lib/layui/css/layui.css')}}">


        <script src="{{URL::asset('resources/xadmin/lib/layui/layui.js')}}" charset="utf-8"></script>
        <script type="text/javascript" src="{{URL::asset('resources/xadmin/js/xadmin.js')}}"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>

        <div class="layui-fluid layui-container" >
            <div class="layui-row ">

            


                <form class="layui-form " >
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>登录名
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="username" name="username" required="" lay-verify="required|username"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>将会成为您唯一的登入名
                      </div>
                  </div>

                    <!-- 这里title是在网页上显示的数据，value是用Ajax发送的实际的值 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>性别</label>
                        <div class="layui-input-block">
                        <input type="radio" name="gender" value="1" title="男" checked="" >
                        <input type="radio" name="gender" value="2" title="女" >
                        <input type="radio" name="gender" value="3" title="保密" >
                        </div>
                    </div>

                  <div class="layui-form-item">
                      <label for="phone" class="layui-form-label">
                          <span class="x-red">*</span>联系方式
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="phone" name="mobile" required="" lay-verify="phone"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>请填写正确的手机号，方便我们联系您
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_email" class="layui-form-label">
                          <span class="x-red">*</span>邮箱
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="L_email" name="email" required="" lay-verify="email"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>
                      </div>
                  </div>
                  <div class="layui-form-item" >
                      <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                      <div class="layui-input-block">

                          @foreach($Role as $key =>$val)
                            @if($val->id==0)
                          <input type="radio" name="role_id" value={{$val->id}} title={{$val->role_name}} checked="">
                            @elseif(($val->id)%3==0)
                          <input type="radio" name="role_id" value={{$val->id}} title={{$val->role_name}}><br >
                             @else
                          <input type="radio" name="role_id" value={{$val->id}} title={{$val->role_name}}>
                             @endif
                          @endforeach
                        {{--<input type="radio" name="role_id" value="1" title="超级管理员" checked="">--}}
                        {{--<input type="radio" name="role_id" value="2" title="编辑人员">--}}
                        {{--<input type="radio" name="role_id" value="3" title="宣传人员" ><br >--}}
                        {{--<input type="radio" name="role_id" value="4" title="组织人员" >--}}
                        {{--<input type="radio" name="role_id" value="5" title="白干员工" >--}}
                        {{--<input type="radio" name="role_id" value="6" title="普通员工" >--}}
                      </div>
                  </div>
                 

                  <div class="layui-form-item">
                      <label for="L_pass" class="layui-form-label">
                          <span class="x-red">*</span>密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_pass" name="password" required="" lay-verify="pass"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          6到12个字符
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                          <span class="x-red">*</span>确认密码
                      </label>
                      <div class="layui-input-inline"><!-- 提交的时候只需要提交密码就可以 -->
                          <input type="password" id="L_repass" /*name="repass"*/ required="" lay-verify="repass"
                          autocomplete="off" class="layui-input">
                      </div>
                  </div>
                <div class="layui-input-item">
                  <div class="layui-input-inline">
                        <label class="layui-form-label">是否启用</label>
                        <div class="layui-input-block">
                        <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|不启用">
                        </div>
                 </div>
                  <div class="layui-input-inline">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="">
                          增加
                      </button>
                  </div>
                </div>
                  
              </form>

            </div>
        </div>
<script>
        layui.use(['form', 'layer'],function() {

                $ = layui.jquery;
                var form = layui.form;
                layer = layui.layer;

                //自定义验证规则
                form.verify({

                    
                    username: [/(.+){2,12}$/,'用户名最少也得俩字啊'],
                    pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    repass: function(value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    }
                });
                //监听radio单选,layui监听事件不如用jq一句话获得
                // form.on('radio(role_id)', function(data){
                //     console.log(data.elem); //得到radio原始DOM对象
                //     console.log(data.value); //被点击的radio的value值
                //     var role_id=data.value;
                // });  

                //监听提交
                form.on('submit(add)',
                function(data) {
                    console.log(data);
                    console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                    console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                    console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                    
                    //console.log($('input[name="gender"]:checked').val());
                    console.log(data.field.status);
                    if(data.field.status=='on')data.field.status='2';
                    else data.field.status='1';
                    
                    //发异步，把数据提交给php
                    $.ajax({
                    url:'{{URL::action('Admin\ManagerController@add')}}',
                    type:'post',
                    data:{add_data:data.field},
                    headers : {
                    'X-CSRF-TOKEN' : $("meta[name='csrf-token']").attr('content')
                    },
                    beforeSend:function () {
                        this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
                    },
                    success:function(data){
                        if(data.status=='error'){
                            layer.msg('Error',{
                                icon:5//失败的表情
                                ,time:1000
                            })
                            //return ;
                        }else{
                            layer.msg('Successful Add!',{
                                icon:6,//成功的表情
                                time:1000
                            },function(){
                                xadmin.father_reload();
                            });
                        }
                    },
                    complete:function(){
                        layer.close(this.layerIndex);
                    }
                })
                    layer.alert("增加成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();

                        // 可以对父窗口进行刷新 
                        xadmin.father_reload();
                    });
                    return false;
                });


            });
</script>

    </body>

</html>
